#!/usr/bin/env bash
# encode utf8

# 注释

function mute() {
	:
}

g='g'

function vari() {
	echo "变量常量"
	a='a'
	g='a_g'
	i=1
	f=0.1
	a=f

	mute a g i f
}

stri() {
	echo "字符串"

	s="a\nb"
	s=a'\n'b
	s="a${s}b"
	s=a${s}b

	lines="
    a
    b
    "
	for line in $lines; do
		mute "$line"
	done

	mute s lines
}

coll() {
	echo "数组集合"

	A=(a b c)
	A[9]=a

	A= #清空变量
	unset A

	A[9]=a

	# 引用数组 ${A[*]}
	# 引用数组元素 ${A[0]}
	# 获取数组长度${#A[*]}	${#A[@]}
	# 获取数组元素长度${#A[3]}

	#也可以"${A[@]}"
	for a in ${A[*]}; do
		mute a
	done
}

proc() {
	echo "流程控制"
	a='a'
	if [[ "$a" == 'a' ]]; then
		:
	else
		:
	fi

	i=0
	while [[ $i -lt 3 ]]; do
		i=$((i + 1)) # == $[i+1]
	done

	VAR="AABB"
	case "${VAR}" in
	AABB)
		mute 'match'
		;;
	*AB* | AA* | *BB)
		mute "MATCH"
		;;
	*)
		mute "UNMATCH"
		;;
	esac
}

func() {
	echo "函数方法"
}

clas() {
	:
}

main() {
	echo "Hello, World!"
	vari
	stri
	coll
	proc
	func
	clas
}

main
